package dietmar.ckm2;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.border.TitledBorder;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JList;
import javax.swing.JButton;



import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class LigaGui extends JFrame {

	private JPanel contentPane;
	private Liga liga;
	private LigaGui ligagui;
	private JList lista = new JList();
	private KlubGui klubgui;
	
	
	/**
	 * Create the frame.
	 */
	@SuppressWarnings("unchecked")
	public LigaGui(Liga liga) {
		this.liga=liga;
		KlubGui klubgui = new KlubGui(this);
		this.klubgui=klubgui;


	
	
		
		
  
		

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblKlasaC = new JLabel("Klasa C");
		lblKlasaC.setFont(new Font("Tahoma", Font.PLAIN, 18));
		lblKlasaC.setBounds(10, 11, 92, 32);
		contentPane.add(lblKlasaC);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(new TitledBorder(new LineBorder(new Color(0, 0, 255), 2), "Edytor", TitledBorder.LEADING, TitledBorder.TOP, null, null), "Edytor", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setBounds(277, 60, 155, 132);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JButton btnDodajKlub = new JButton("Dodaj Klub");
		btnDodajKlub.setBounds(10, 21, 135, 23);
		panel_1.add(btnDodajKlub);
		btnDodajKlub.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dodaj();
				  
				
			}
		});
		
		JButton btnEdytujKlub = new JButton("Edytuj Klub");
	
		btnEdytujKlub.setBounds(10, 55, 135, 23);
		panel_1.add(btnEdytujKlub);
		btnEdytujKlub.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				edytuj();	
				
			}
		});
		
		JButton btnUsunKlub = new JButton("Usun Klub");
		btnUsunKlub.setBounds(10, 89, 135, 23);
		panel_1.add(btnUsunKlub);
		btnUsunKlub.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
		     usun();
		     odswiez();
		
			}
		});
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 61, 257, 195);
		contentPane.add(panel);
		panel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 255), 2), "Tabela", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setLayout(null);
		
	
		lista.setBounds(10, 21, 237, 163);
		panel.add(lista);
		lista.setListData(liga.liga);
	
     
	}
	void dodaj()
	{
	
		klubgui.setVisible(true);

	}
	void edytuj()
	{
	
		klubgui.setVisible(true);

	}
	
	void odswiez()
	{
		lista.setListData(liga.liga);
	}

	void usun()
	{
		liga.usunKlub(lista.getSelectedIndex());
	}


	public Liga getLiga() {
		return liga;
	}

	public void setLiga(Liga liga) {
		this.liga = liga;
	}

	public LigaGui getLigagui() {
		return ligagui;
	}

	public void setLigagui(LigaGui ligagui) {
		this.ligagui = ligagui;
	}



	public JList getLista() {
		return lista;
	}

	public void setLista(JList lista) {
		this.lista = lista;
	}
	

}
